GtkStyleContext: Don crash on empty class sets.
authorCarlos Garnacho <carlosg@gnome.org>
Sun, 18 Jul 2010 16:40:48 +0000 (18:40 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Sat, 4 Dec 2010 14:37:19 +0000 (15:37 +0100)
gtk/gtkstylecontext.c

index 71f8c83a607faeab953c6fa98ae56469929bd465..c1ec55dd7e65496c7dd96ea5b460f720749a1c72 100644 (file)
@@ -642,16 +642,21 @@ gtk_style_context_restore (GtkStyleContext *context)
 }
 
 static gboolean
-style_class_find (GArray       *array,
-                  GQuark        class_quark,
-                  guint        *position)
+style_class_find (GArray *array,
+                  GQuark  class_quark,
+                  guint  *position)
 {
   guint min, max, mid;
   gboolean found = FALSE;
 
+  if (position)
+    *position = 0;
+
+  if (!array || array->len == 0)
+    return FALSE;
+
   min = 0;
   max = array->len - 1;
-  mid = max - min / 2;
 
   do
     {
@@ -676,16 +681,21 @@ style_class_find (GArray       *array,
 }
 
 static gboolean
-child_style_class_find (GArray       *array,
-                        GQuark        class_quark,
-                        guint        *position)
+child_style_class_find (GArray *array,
+                        GQuark  class_quark,
+                        guint  *position)
 {
   guint min, max, mid;
   gboolean found = FALSE;
 
+  if (position)
+    *position = 0;
+
+  if (!array || array->len == 0)
+    return FALSE;
+
   min = 0;
   max = array->len - 1;
-  mid = max - min / 2;
 
   do
     {